package com.bilibili.controller;


import com.alipay.easysdk.kernel.Config;
import com.alipay.easysdk.payment.page.models.AlipayTradePagePayResponse;
import com.bilibili.dto.AliPayHtmlDto;
import com.bilibili.exception.BusinessException;
import com.bilibili.manage.AliPayService;
import com.bilibili.vo.AliPayVo;
import com.bilibili.vo.UserLoginVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@Controller
@RestController
public class PayController {
    @Autowired
    private AliPayService aliPayService;

    /**
     * 支付操作
     *
     * @param res 响应对象
     */
    @RequestMapping(value = "pay", method = RequestMethod.POST)
    public AliPayHtmlDto pay(HttpServletResponse res, @RequestBody AliPayVo aliPayVo) {
        AlipayTradePagePayResponse response = aliPayService.payOrder(aliPayVo);
        AliPayHtmlDto aliPayHtmlDto = new AliPayHtmlDto();
        aliPayHtmlDto.setPayHtml(response.getBody());
        return aliPayHtmlDto;
    }
}